library("tuneR")
library("seewave")
library("reticulate")
use_python("C:\\Users\\01143557\\AppData\\Local\\Programs\\Python\\Python39\\python.exe", required = TRUE)
library(signal, warn.conflicts = F, quietly = T)
library(oce, warn.conflicts = F, quietly = T)
## Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1
meski <- readWave("sample.wav")
zenski <- readWave("mamiko.wav")
filter <- function(wave){
wave <- ffilter(wave, from=0, to=280)
wave
}
duration <- function(sample){
dur = length(sample@left)/sample@samp.rate
dur
}
sample_rate <- function(sample){
fs = sample@samp.rate
fs
}
frequency_plot <- function(sample){
plot(sample@left[30700:31500], type = "l", main = "Sample",
xlab = "Time", ylab = "Frequency")
}
waveform <- function(sample){
sl <- sample@left
sl = sl - mean(sl)
plot(sl, type = 'l', xlab = 'Samples', ylab = 'Amplitude')
}
spectogram <- function(sample){
sl <- sample@left
spec = specgram(x = sl,
n = 1024,
Fs = sample_rate(sample),
window = 256,
overlap = 128)
P = abs(spec$S)
P = P/max(P)
P = 10*log10(P)
t = spec$t
imagep(x = t, y = spec$f, z = t(P), col = oce.colorsViridis,
ylab = 'Frequency [Hz]', xlab = 'Time [s]', drawPalette = T, decimate = F)
}
to_data_frame <- function(sample){
filtered_glos <- filter(sample)
specprop(meanspec(filtered_glos, f= 44100), f=44100)
minfun <- min(fund(sample, fmax=280)[,2], na.rm=TRUE)
meanfun <- mean(fund(sample, fmax=280)[,2], na.rm=TRUE)
df <- data.frame(specprop(meanspec(filtered_glos, f= 44100), f=44100), "meanfun" <- meanfun, "minfun" <- minfun)
colnames(df)[1] <- c("meanfreq")
colnames(df)[15:16] <- c("meanfun", "minfun")
colnames(df)[9] <- c("centroid")
colnames(df)[13] <- c("sp.ent")
df
}
duration(meski)
## [1] 7.692222
duration(zenski)
## [1] 9.080499
sample_rate(meski)
## [1] 44100
sample_rate(zenski)
## [1] 44100
waveform(meski)
##### zenski
waveform(zenski)
frequency_plot(meski)
frequency_plot(zenski)
spectogram(meski)
spectogram(zenski)
meski_df
zenski_df
import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
import matplotlib
import requests
df=requests.get("https://api.apispreadsheets.com/api/dataset/gender-voice/").json()
from pandas import json_normalize
voice_df = json_normalize(df, 'data')
voice_df.head()
## meanfreq sd median Q25 ... maxdom dfrange modindx label
## 0 0.059781 0.064241 0.032027 0.015071 ... 0.007812 0.000000 0.000000 male
## 1 0.066009 0.067310 0.040229 0.019414 ... 0.054688 0.046875 0.052632 male
## 2 0.077316 0.083829 0.036718 0.008701 ... 0.015625 0.007812 0.046512 male
## 3 0.151228 0.072111 0.158011 0.096582 ... 0.562500 0.554688 0.247119 male
## 4 0.135120 0.079146 0.124656 0.078720 ... 5.484375 5.476562 0.208274 male
##
## [5 rows x 21 columns]
voice_df.info()
## <class 'pandas.core.frame.DataFrame'>
## RangeIndex: 3168 entries, 0 to 3167
## Data columns (total 21 columns):
## # Column Non-Null Count Dtype
## --- ------ -------------- -----
## 0 meanfreq 3168 non-null float64
## 1 sd 3168 non-null float64
## 2 median 3168 non-null float64
## 3 Q25 3168 non-null float64
## 4 Q75 3168 non-null float64
## 5 IQR 3168 non-null float64
## 6 skew 3168 non-null float64
## 7 kurt 3168 non-null float64
## 8 sp.ent 3168 non-null float64
## 9 sfm 3168 non-null float64
## 10 mode 3168 non-null float64
## 11 centroid 3168 non-null float64
## 12 meanfun 3168 non-null float64
## 13 minfun 3168 non-null float64
## 14 maxfun 3168 non-null float64
## 15 meandom 3168 non-null float64
## 16 mindom 3168 non-null float64
## 17 maxdom 3168 non-null float64
## 18 dfrange 3168 non-null float64
## 19 modindx 3168 non-null float64
## 20 label 3168 non-null object
## dtypes: float64(20), object(1)
## memory usage: 519.9+ KB
voice_df.hist(figsize=(18, 12), bins=30);
plt.show()
sns.set(font_scale=2.5)
fig, ax = plt.subplots(figsize = (30, 25))
sns.heatmap(round(abs(voice_df.corr()), 2), cmap="cividis", annot = True, vmin=0, vmax=1, linewidths=1, linecolor='white', annot_kws={"fontsize":20});
plt.show()
sns.set(font_scale=1)
g = sns.pairplot(voice_df[['sd', 'IQR', 'meanfun', 'Q25', 'label']], hue = 'label', height = 3, plot_kws = {'alpha': 0.6})
g.map_lower(sns.kdeplot, levels=4, color=".2");
plt.show()
def ridgeplot(voice_df, label1):
rp = sns.FacetGrid(voice_df, row="label", hue="label", aspect=5, height=1.25)
rp.map(sns.kdeplot, label1, bw_adjust=.5, clip_on=False, fill=True, alpha=1, linewidth=1.5)
rp.map(sns.kdeplot, label1, clip_on=False, color="w", lw=2, bw_adjust=.5)
rp.map(plt.axhline, y=0, lw=2, clip_on=False)
def label(x, color, label):
ax = plt.gca()
ax.text(0, .2, label, fontweight="bold", color=color, ha="left", va="center", transform=ax.transAxes)
rp.map(label, label1)
rp.set_titles("")
rp.despine(bottom=True, left=True)
rp.fig.tight_layout()
cols = voice_df.columns.values[0:18].tolist
ridgeplot(voice_df, "dfrange")
plt.show()
ridgeplot(voice_df, "modindx")
plt.show()